package pro.spring.controller.frontController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import pro.spring.model.Information;
import pro.spring.vo.PaginationVo;

@Controller("YoukuController")
@RequestMapping("/youku")
public class YoukuController extends BaseController {
	String local="page/front/come/";
	@RequestMapping("/uploadvedio.html")
	public String uploadVedio(ModelMap map){
		//id10为vediotoken的id
		String vediotoken= adminService.selectByNameForVedio("vediotoken").getaPassword();
		map.put("vediotoken", vediotoken);
		return local+"uploadvedio";
	}
	@RequestMapping("/vedio")
	public String vedio(){
		return local+"vedio";
	}
	@ResponseBody
	@RequestMapping(value="upload.json",method=RequestMethod.POST)
	public Integer upload(Information information,HttpServletRequest request){
		HttpSession session=request.getSession();
		Integer usersUId = (Integer)session.getAttribute("uId");
		information.setUsersUId(usersUId);
		information.setInType(information.getInType()+200);
		return youkuService.insert(information);
	}
	@ResponseBody
	@RequestMapping(value="vediobroswer.html",method=RequestMethod.POST)
	public void vediobroswer(String vedioId){
		youkuService.addBroswer(vedioId);
	}
	
	
	@RequestMapping(value="morevedio",method=RequestMethod.GET)
	public String list(@RequestParam(value = "p", defaultValue = "1")Integer pagenum,Integer offset,ModelMap map){
		if(offset==null){
			offset=1;
		}
		PaginationVo<Information> allvedio=youkuService.getPaginationInfo(pagenum,12);
		map.put("all",allvedio);
		map.put("type", "视频列表");
		return local+"morevedio";
	}
	

}
